#include "SMPPBroadcastSM.hpp"

using namespace smpp::pdu;

BroadcastSM::BroadcastSM(const Header &nHeader,
const CoctetString &nServiceType,
const quint8 nSourceAddrTON,
const quint8 nSourceAddrNPI,
const CoctetString &nSourceAddr,
const CoctetString &nMessageId,
const quint8 nPriorityFlag,
const CoctetString &nScheduleDeliveryTime,
const CoctetString &nValidityPeriod,
const quint8 nReplaceIfPresentFlag,
const quint8 nDataCoding,
const quint8 nSMDefaultMsgId,
const BroadcastAreaIdentifier *nBroadcastAreaIdentifier,
const BroadcastContentType *nBroadcastContentType,
const BroadcastRepNum *nBroadcastRepNum,
const BroadcastFrequencyInterval *
nBroadcastFrequencyInterval,
const BroadcastRequestOptionalTLVs &nBroadcastRequestOptionalTLVs):
Header(nHeader),
_ServiceType(nServiceType),
_SourceAddrTON(nSourceAddrTON),
_SourceAddrNPI(nSourceAddrNPI),
_SourceAddr(nSourceAddr),
_MessageId(nMessageId),
_PriorityFlag(nPriorityFlag),
_ScheduleDeliveryTime(nScheduleDeliveryTime),
_ValidityPeriod(nValidityPeriod),
_ReplaceIfPresentFlag(nReplaceIfPresentFlag),
_DataCoding(nDataCoding),
_SMDefaultMsgId(nSMDefaultMsgId),
_BroadcastAreaIdentifier(0),
_BroadcastContentType(0),
_BroadcastRepNum(0),
_BroadcastFrequencyInterval(0),
BroadcastRequestOptionalTLVs(nBroadcastRequestOptionalTLVs){
	if(nBroadcastAreaIdentifier)
		_BroadcastAreaIdentifier = 
		new BroadcastAreaIdentifier(*nBroadcastAreaIdentifier);
	if(nBroadcastContentType)
		_BroadcastContentType = 
		new BroadcastContentType(*nBroadcastContentType);
	if(nBroadcastRepNum)
		_BroadcastRepNum = 
		new BroadcastRepNum(*nBroadcastRepNum);
	if(nBroadcastFrequencyInterval)
		_BroadcastFrequencyInterval = 
		new BroadcastFrequencyInterval(*nBroadcastFrequencyInterval);
}

BroadcastSM::BroadcastSM(const BroadcastSM &nBroadcastSM):
Header(nBroadcastSM),
_ServiceType(nBroadcastSM.getServiceType()),
_SourceAddrTON(nBroadcastSM.getSourceAddrTON()),
_SourceAddrNPI(nBroadcastSM.getSourceAddrNPI()),
_SourceAddr(nBroadcastSM.getSourceAddr()),
_MessageId(nBroadcastSM.getMessageId()),
_PriorityFlag(nBroadcastSM.getPriorityFlag()),
_ScheduleDeliveryTime(nBroadcastSM.getScheduleDeliveryTime()),
_ValidityPeriod(nBroadcastSM.getValidityPeriod()),
_ReplaceIfPresentFlag(nBroadcastSM.getReplaceIfPresentFlag()),
_DataCoding(nBroadcastSM.getDataCoding()),
_SMDefaultMsgId(nBroadcastSM.getSMDefaultMsgId()),
_BroadcastAreaIdentifier(0),
_BroadcastContentType(0),
_BroadcastRepNum(0),
_BroadcastFrequencyInterval(0),
BroadcastRequestOptionalTLVs(nBroadcastSM){
	if(nBroadcastSM.getBroadcastAreaIdentifier())
		_BroadcastAreaIdentifier = new BroadcastAreaIdentifier(
		*nBroadcastSM.getBroadcastAreaIdentifier());
	if(nBroadcastSM.getBroadcastContentType())
		_BroadcastContentType = new BroadcastContentType(
		*nBroadcastSM.getBroadcastContentType());
	if(nBroadcastSM.getBroadcastRepNum())
		_BroadcastRepNum = new BroadcastRepNum(
		*nBroadcastSM.getBroadcastRepNum());
	if(nBroadcastSM.getBroadcastFrequencyInterval())
		_BroadcastFrequencyInterval = new BroadcastFrequencyInterval(
		*nBroadcastSM.getBroadcastFrequencyInterval());
}

BroadcastSM::~BroadcastSM(){
	if(_BroadcastAreaIdentifier)
		delete _BroadcastAreaIdentifier;
	if(_BroadcastContentType)
		delete _BroadcastContentType;
	if(_BroadcastRepNum)
		delete _BroadcastRepNum;
	if(_BroadcastFrequencyInterval)
		delete _BroadcastFrequencyInterval;
}

void BroadcastSM::setServiceType(const CoctetString &nServiceType){
	_ServiceType = nServiceType;
}

const CoctetString &BroadcastSM::getServiceType() const{
	return _ServiceType;
}

void BroadcastSM::setSourceAddrTON(const quint8 nSourceAddrTON){
	_SourceAddrTON = nSourceAddrTON;
}

const quint8 BroadcastSM::getSourceAddrTON() const{
	return _SourceAddrTON;
}

void BroadcastSM::setSourceAddrNPI(const quint8 nSourceAddrNPI){
	_SourceAddrNPI = nSourceAddrNPI;
}

const quint8 BroadcastSM::getSourceAddrNPI() const{
	return _SourceAddrNPI;
}

void BroadcastSM::setSourceAddr(const CoctetString &nSourceAddr){
	_SourceAddr = nSourceAddr;
}

const CoctetString &BroadcastSM::getSourceAddr() const{
	return _SourceAddr;
}

void BroadcastSM::setMessageId(const CoctetString &nMessageId){
	_MessageId = nMessageId;
}

const CoctetString &BroadcastSM::getMessageId() const{
	return _MessageId;
}

void BroadcastSM::setPriorityFlag(const quint8 nPriorityFlag){
	_PriorityFlag = nPriorityFlag;
}

const quint8 BroadcastSM::getPriorityFlag() const{
	return _PriorityFlag;
}

void BroadcastSM::setScheduleDeliveryTime(
	const CoctetString &nScheduleDeliveryTime){
	_ScheduleDeliveryTime = nScheduleDeliveryTime;
}

const CoctetString &BroadcastSM::getScheduleDeliveryTime() const{
	return _ScheduleDeliveryTime;
}

void BroadcastSM::setValidityPeriod(
	const CoctetString &nValidityPeriod){
	_ValidityPeriod = nValidityPeriod;
}

const CoctetString &BroadcastSM::getValidityPeriod() const{
	return _ValidityPeriod;
}

void BroadcastSM::setReplaceIfPresentFlag(
	const quint8 nReplaceIfPresentFlag){
	_ReplaceIfPresentFlag = nReplaceIfPresentFlag;
}

const quint8 BroadcastSM::getReplaceIfPresentFlag() const{
	return _ReplaceIfPresentFlag;
}

void BroadcastSM::setDataCoding(const quint8 nDataCoding){
	_DataCoding = nDataCoding;
}

const quint8 BroadcastSM::getDataCoding() const{
	return _DataCoding;
}

void BroadcastSM::setSMDefaultMsgId(const quint8 nSMDefaultMsgId){
	_SMDefaultMsgId = nSMDefaultMsgId;
}

const quint8 BroadcastSM::getSMDefaultMsgId() const{
	return _SMDefaultMsgId;
}

void BroadcastSM::setBroadcastAreaIdentifier(
	const BroadcastAreaIdentifier *nBroadcastAreaIdentifier){
	if(_BroadcastAreaIdentifier){
		delete _BroadcastAreaIdentifier;
		_BroadcastAreaIdentifier = 0;
	}
	if(nBroadcastAreaIdentifier)
		_BroadcastAreaIdentifier = 
		new BroadcastAreaIdentifier(*nBroadcastAreaIdentifier);
}

const BroadcastAreaIdentifier *
	BroadcastSM::getBroadcastAreaIdentifier() const{
	return _BroadcastAreaIdentifier;
}

void BroadcastSM::setBroadcastContentType(
	const BroadcastContentType *nBroadcastContentType){
	if(_BroadcastContentType){
		delete _BroadcastContentType;
		_BroadcastContentType = 0;
	}
	if(nBroadcastContentType)
		_BroadcastContentType = 
		new BroadcastContentType(*nBroadcastContentType);	
}

const BroadcastContentType *
	BroadcastSM::getBroadcastContentType() const{
	return _BroadcastContentType;
}

void BroadcastSM::setBroadcastRepNum(
	const BroadcastRepNum *nBroadcastRepNum){
	if(_BroadcastRepNum){
		delete _BroadcastRepNum;
		_BroadcastRepNum = 0;
	}
	if(nBroadcastRepNum)
		_BroadcastRepNum = 
		new BroadcastRepNum(*nBroadcastRepNum);
}

const BroadcastRepNum *
	BroadcastSM::getBroadcastRepNum() const{
	return _BroadcastRepNum;
}

void BroadcastSM::setBroadcastFrequencyInterval(
	const BroadcastFrequencyInterval *nBroadcastFrequencyInterval){
	if(_BroadcastFrequencyInterval){
		delete _BroadcastFrequencyInterval;
		_BroadcastFrequencyInterval = 0;
	}
	if(nBroadcastFrequencyInterval)
		_BroadcastFrequencyInterval = 
		new BroadcastFrequencyInterval(*nBroadcastFrequencyInterval);
}

const BroadcastFrequencyInterval *
	BroadcastSM::getBroadcastFrequencyInterval() const{
	return _BroadcastFrequencyInterval;
}

void BroadcastSM::calcCommandLength(){
	_CommandLength = 22 + _ServiceType.size() + _SourceAddr.size() 
		+ _MessageId.size() + _ValidityPeriod.size() + 
		_ScheduleDeliveryTime.size() + 
		BroadcastRequestOptionalTLVs::getLength();
	if(_BroadcastAreaIdentifier)
		_CommandLength += _BroadcastAreaIdentifier->getLength();
	if(_BroadcastContentType)
		_CommandLength += _BroadcastContentType->getLength();
	if(_BroadcastRepNum)
		_CommandLength += _BroadcastRepNum->getLength();
	if(_BroadcastFrequencyInterval)
		_CommandLength += _BroadcastFrequencyInterval->getLength();
}
